home *** CD-ROM | disk | FTP | other *** search
/ The Fatted Calf / The Fatted Calf.iso / Applications / GraphicViewers / pCD / Source / hpcdtoppm.0.4 / output.c < prev    next >
C/C++ Source or Header  |  1993-03-23  |  4KB  |  184 lines

  1. /* hpcdtoppm (Hadmut's pcdtoppm) v0.4
  2. *  Copyright (c) 1992, 1993 by Hadmut Danisch (danisch@ira.uka.de).
  3. *  Permission to use and distribute this software and its
  4. *  documentation for noncommercial use and without fee is hereby granted,
  5. *  provided that the above copyright notice appear in all copies and that
  6. *  both that copyright notice and this permission notice appear in
  7. *  supporting documentation. It is not allowed to sell this software in 
  8. *  any way. This software is not public domain.
  9. */
  10.  
  11. #include "hpcdtoppm.h"
  12.  
  13.  
  14.  
  15. static void flip_corr(w,h,ptr,ystep,xstep)
  16.   sdim w,h,*ystep,*xstep;
  17.   uBYTE **ptr;
  18.  {
  19.   if(flvert) 
  20.    { (*ptr) += (h-1)* (*ystep);
  21.      (*ystep) = -(*ystep);
  22.    }
  23.  
  24.   if(flhori)
  25.    {(*ptr) += (w-1)* (*xstep);
  26.     (*xstep) = -(*xstep);
  27.    }
  28.  }
  29.  
  30.  
  31. static void call_1plane(proc,w,h, ptr,zeil,pix) 
  32.   void (*proc)();
  33.   sdim w,h, zeil,pix;
  34.   uBYTE *ptr;
  35.  {
  36.   flip_corr(w,h,&ptr,&zeil,&pix);
  37.   (*proc)(w,h,ptr,zeil,pix);
  38.  }
  39.  
  40.  
  41. static void do_1plane(proc,w,h,g,t)
  42.   void (*proc)();
  43.   dim w,h;
  44.   implane *g;
  45.   enum TURNS t;
  46.  {
  47.    switch(t)
  48.     {case T_NONE: call_1plane(proc,w,h,g->im,g->mwidth,1);
  49.                   break;
  50.      case T_RIGHT:call_1plane(proc,h,w,g->im + g->mwidth * ( g->iheight - 1) , 1 , -(g->mwidth));
  51.                   break;
  52.      case T_LEFT: call_1plane(proc,h,w,g->im + g->iwidth - 1 , -1 , (g->mwidth));
  53.                   break; 
  54.      default:error(E_INTERN);
  55.     }
  56.  
  57.  }
  58.  
  59.  
  60.  
  61. static void call_3plane(proc,w,h, rptr,rzeil,rpix,  
  62.                                gptr,gzeil,gpix,  
  63.                                bptr,bzeil,bpix) 
  64.   void (*proc)();
  65.   sdim w,h, rzeil,gzeil,bzeil, rpix,gpix,bpix;
  66.   uBYTE *rptr,*gptr,*bptr;
  67.  {
  68.   flip_corr(w,h,&rptr,&rzeil,&rpix);
  69.   flip_corr(w,h,&gptr,&gzeil,&gpix);
  70.   flip_corr(w,h,&bptr,&bzeil,&bpix);
  71.  
  72.   (*proc)(w,h,rptr,rzeil,rpix,gptr,gzeil,gpix,bptr,bzeil,bpix );
  73.  }
  74.  
  75.  
  76. static void do_3plane(proc,w,h,r,g,b,t)
  77.   void (*proc)();
  78.   dim w,h;
  79.   implane *r,*g,*b;
  80.   enum TURNS t;
  81.  {
  82.    switch(t)
  83.     {case T_NONE: call_3plane(proc,w,h,r->im,r->mwidth,1,
  84.                                        g->im,g->mwidth,1,
  85.                                        b->im,b->mwidth,1);
  86.                   break;     
  87.      case T_RIGHT:call_3plane(proc,h,w,r->im + r->mwidth * ( r->iheight - 1) , 1 , -(r->mwidth),
  88.                                        g->im + g->mwidth * ( g->iheight - 1) , 1 , -(g->mwidth),
  89.                                        b->im + b->mwidth * ( b->iheight - 1) , 1 , -(b->mwidth));
  90.                   break;     
  91.      case T_LEFT: call_3plane(proc,h,w,r->im + r->iwidth - 1 , -1 , (r->mwidth),
  92.                                        g->im + g->iwidth - 1 , -1 , (g->mwidth),
  93.                                        b->im + b->iwidth - 1 , -1 , (b->mwidth));
  94.                               break;           
  95.      default:error(E_INTERN);
  96.     }
  97.  
  98.  }
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105. void writepicture(w,h,r,g,b,t)
  106.   dim w,h;
  107.   implane *r,*g,*b;
  108.   enum TURNS t;
  109.  {
  110.  
  111.   melde("writepicture\n");
  112.      if((!r) || (r->iwidth != w ) || (r->iheight != h) || (!r->im)) error(E_INTERN);
  113.   
  114.   if(!monochrome)
  115.    {
  116.      if((!g) || (g->iwidth != w ) || (g->iheight != h) || (!g->im)) error(E_INTERN);
  117.      if((!b) || (b->iwidth != w ) || (b->iheight != h) || (!b->im)) error(E_INTERN);
  118.    }
  119.  
  120.   switch(outfor)
  121.    {case O_YCC:
  122.     case O_PPM:  do_3plane(write_ppm     ,w,h,r,g,b,t); break;
  123.     case O_PS:   do_3plane(write_psrgb   ,w,h,r,g,b,t); break;
  124.     case O_EPS:  do_3plane(write_epsrgb  ,w,h,r,g,b,t); break;
  125.  
  126.     case O_PGM:  do_1plane(write_pgm     ,w,h,r,t);     break;
  127.     case O_PSG:  do_1plane(write_psgrey  ,w,h,r,t);     break;
  128.     case O_EPSG: do_1plane(write_epsgrey ,w,h,r,t);     break;
  129.  
  130.     default: error(E_INTERN);
  131.    }
  132.  
  133.  
  134.  }
  135.  
  136.  
  137.  
  138.  
  139.  
  140.  
  141.  
  142.  
  143.  
  144. struct ph1 
  145.  {char  id1[8];
  146.   uBYTE ww1[14];
  147.   char  id2[20];
  148.   char  id3[4*16+4];
  149.   short ww2;
  150.   char  id4[20];
  151.   uBYTE ww3[2*16+1];
  152.   char  id5[4*16];
  153.   uBYTE idx[11*16];
  154.  } ;
  155.  
  156.  
  157. void druckeid()
  158. {struct ph1 *d;
  159.  char ss[100];
  160.  
  161.  d=(struct ph1 *)sbuffer;
  162.  
  163. #define dr(feld,kennung)   \
  164.      strncpy(ss,feld,sizeof(feld));\
  165.      ss[sizeof(feld)]=0;\
  166.      fprintf(stderr,"%s: %s \n",kennung,ss);
  167.  
  168.  
  169. dr(d->id1,"Id1")
  170. dr(d->id2,"Id2")
  171. dr(d->id3,"Id3")
  172. dr(d->id4,"Id4")
  173. dr(d->id5,"Id5")
  174.  
  175. #undef dr 
  176.  
  177. }
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184.